package com.java复习.代理;

/*
静态代理举例
特点：代理类和被代理类在编译期间，就确定下来了
 */

interface ClothFactory{
    void produceCloth();
}

// 代理类
class proxyClothFactory implements ClothFactory{

    private ClothFactory factory; //用被代理对象进行实例化

    public proxyClothFactory(ClothFactory factory){
        this.factory = factory;
    }

    @Override
    public void produceCloth() {
        System.out.println("代理工厂做一下工作");
        factory.produceCloth();
        System.out.println("代理工厂做一下后续收尾工作");
    }
}

// 被代理类
class NikeClothFactory implements ClothFactory{

    @Override
    public void produceCloth() {
        System.out.println("nike工厂生产一批衣服");
    }
}

public class StaticProduceTest {
    public static void main(String[] args) {
        // 创建被代理类对象
        ClothFactory nike = new NikeClothFactory();
        // 创建代理类对象
        ClothFactory proxyClothFactory = new proxyClothFactory(nike);
        proxyClothFactory.produceCloth();
    }
}
